#include "setnonblock.hpp"
//将stdin调整为非阻塞模式
using namespace std;
int main(){
    SetNonBlock(0);
    char buffer[1024];
    for(;;){
        ssize_t r = read(0,buffer,sizeof buffer);
        if(r > 0){
            //读到数据
            buffer[r-1] = 0;
            cout<<"echo#:"<<buffer<<endl;
        }else if(r == 0){
            //读到结尾EOF
            cout<<"read end!"<<endl;
            break;
        }else{
            //-1:错误或者非阻塞
            if(errno == EAGAIN | EWOULDBLOCK)   cout<<"nonblock!"<<strerror(errno)<<errno<<endl;
            else if(errno == EINTR) cout<<"signal inter"<<endl;
            else{
                cerr<<"read faild!"<<endl;
            }
            sleep(1);
        }
    }
    
}